﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace TiecCuoi
{
    public partial class Login : Form
    {
        public bool Flag = false;
        //Data base
        private SqlConnection _CNN;
        public Login(SqlConnection cnn)
        {
            _CNN = cnn;
            InitializeComponent();
        }

        private void B_Cancel_Click(object sender, EventArgs e)
        {
            Flag = false;
            this.Close();
        }

        private void B_OK_Click(object sender, EventArgs e)
        {
            bool a = true;

                try
                {
                    string ham = "select MatKhau from Taikhoan where MatKhau='" + TB_matkhau.Text.Trim() + "'";
                    SqlCommand select = new SqlCommand(ham, _CNN);
                    SqlDataReader read = select.ExecuteReader();
                    if (read.Read())
                    {
                        Flag = true;
                    }
                    else
                    {
                        Flag = false;
                        if (MessageBox.Show("Bạn có muốn nhập lại không?", "Mật khẩu sai", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                        {
                            a = false;
                            this.Close();
                        }
                        else
                        {
                            TB_matkhau.Text = "";
                            TB_matkhau.Focus();
                        }

                    }
                    read.Close();
                    select.Dispose();
                    read.Dispose();
                    if (Flag)
                    {
                        this.Close();
                    }
                }
                catch (Exception e1)
                {
                    MessageBox.Show(e1.Message);
                    Flag = false;
                }
            
        }
    }
}
